﻿using System;
using DatabaseGroup.SSIS.SourceAdapters.View;

namespace DatabaseGroup.SSIS.SourceAdapters.Presenter
{
    /// <summary>
    /// Presenter for handling the Main tab view
    /// </summary>
    public class MainPresenter
    {
        private readonly IEditorMainView _view;

        /// <summary>
        /// Initializes a new instance of the MainTabPresenter class
        /// using the view
        /// </summary>
        /// <param name="view">An instance of an IEditorMainView</param>
        public MainPresenter(IEditorMainView view)
        {
            _view = view;

            view.CancelSettings += view_CancelSettings;
            view.SavedSettings += view_SavedSettings;
        }

        /// <summary>
        /// Closes the view with a DialogResult OK
        /// </summary>
        /// <param name="sender">The View</param>
        /// <param name="e"></param>
        private void view_SavedSettings(object sender, EventArgs e)
        {
            _view.CloseView(true);
        }

        /// <summary>
        /// Closes the view with a DialogResult Cancel
        /// </summary>
        /// <param name="sender">The View</param>
        /// <param name="e"></param>
        private void view_CancelSettings(object sender, EventArgs e)
        {
            _view.CloseView(false);
        }
    }
}
